import Vue from 'vue'
import VueRouter from 'vue-router'
const login = () =>
    import ( /* webpackChunkName: "login_home_welcome" */ '../components/login.vue')
const home = () =>
    import ( /* webpackChunkName: "login_home_welcome" */ '../components/home.vue')
const welcome = () =>
    import ( /* webpackChunkName: "login_home_welcome" */ '../components/welcome.vue')

const Users = () =>
    import ( /* webpackChunkName: "Users_Rights_Roles" */ '../components/user/Users.vue')
const Rights = () =>
    import ( /* webpackChunkName: "Users_Rights_Roles" */ '../components/power/rights.vue')
const Roles = () =>
    import ( /* webpackChunkName: "Users_Rights_Roles" */ '../components/power/roles.vue')

const Cate = () =>
    import ( /* webpackChunkName: "Cate_Params" */ '../components/good/cate.vue')
const Params = () =>
    import ( /* webpackChunkName: "Cate_Params" */ '../components/good/params.vue')

const GoodsList = () =>
    import ( /* webpackChunkName: "GoodsList_Add" */ '../components/good/list.vue')
const Add = () =>
    import ( /* webpackChunkName: "GoodsList_Add" */ '../components/good/add.vue')

const Order = () =>
    import ( /* webpackChunkName: "Order_Report" */ '../components/order/order.vue')
const Report = () =>
    import ( /* webpackChunkName: "Order_Report" */ '../components/report/report.vue')



// import login from '../components/login.vue'
// import home from '../components/home.vue'
// import welcome from '../components/welcome.vue'
// import Users from '../components/user/Users.vue'
// import Rights from '../components/power/rights.vue'
// import Roles from '../components/power/roles.vue'
// import Cate from '../components/good/cate.vue'
// import Params from '../components/good/params.vue'
// import GoodsList from '../components/good/list.vue'
// import Add from '../components/good/add.vue'
// import Order from '../components/order/order.vue'
// import Report from '../components/report/report.vue'


Vue.use(VueRouter)

const routes = [
    { path: '/', redirect: '/login' },
    { path: '/login', component: login },
    {
        path: '/home',
        component: home,
        redirect: '/welcome',
        children: [
            { path: '/welcome', component: welcome },
            { path: '/users', component: Users },
            { path: '/rights', component: Rights },
            { path: '/roles', component: Roles },
            { path: '/categories', component: Cate },
            { path: '/params', component: Params },
            { path: '/goods', component: GoodsList },
            { path: '/goods/add', component: Add },
            { path: '/orders', component: Order },
            { path: '/reports', component: Report },

        ]
    }
]

const router = new VueRouter({
    routes
})
router.beforeEach((to, from, text) => {
    if (to.path === '/login') return text();
    const tokenStr = window.sessionStorage.getItem('token');
    if (!tokenStr) return text('/login')
    text()
})
export default router